<template>
  <div style="min-height:400px">
    <el-checkbox v-if="havehuiyidata" v-model="dosyspinggu" style="margin-bottom:20px;">会议数据已存在，更新数据时重新进行系统评估</el-checkbox>
    <el-upload class="upload-demo" :before-upload="beforeAvatarUpload" :on-success="getUploadResult"
        :action="this.$http.defaults.baseURL + 'shenghuohui2020/uploadunitdatafile/' + this.$route.params.id+'?operation='+this.operation+'&dosyspinggu='+ this.dosyspinggu" with-credentials accept=".mzshh" :limit="1" :file-list="fileList" style="width:400px" >
      <el-button type="primary" icon="el-icon-document">点击上传</el-button>
      <div slot="tip" class="el-upload__tip">只能上传扩展名为mzshh的民主生活会数据包文件</div>
    </el-upload>
    <el-dialog title="导入失败，问题如下：" width="98%" top="20px" :visible.sync="errorListVisible">
      <el-table ref="errorList" :data="errorList" highlight-current-row v-loading="errorListLoading" style="width: 100%;">
        <el-table-column type="index" label="序号" width="70">
        </el-table-column>
        <el-table-column prop="TheError" label="问题">
        </el-table-column>
      </el-table>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="errorListVisible = false">取消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  components: {
  },
  props: {
    operation: '',
    havehuiyidata: ''
  },
  data () {
    return {
      fileList: [],
      errorList: [],
      errorListLoading: false,
      errorListVisible: false,
      dosyspinggu: false
    }
  },
  methods: {
    getUploadResult (res) {
      if (res.IsSuccess === true) {
        this.$alert(res.Msg, '导入成功', {
          confirmButtonText: '确定',
          type: 'success'
        })
        this.$emit('refreshevent')
      } else {
        console.log(res.Msg)
        if (res.Msg === 'ok') {
          this.errorListVisible = true
          this.errorList = res.Result
        } else {
          this.$alert(res.Msg, '导入失败', {
            confirmButtonText: '确定',
            type: 'error'
          })
        }
      }
      this.fileList = []
    },
    beforeAvatarUpload (file) {
      console.log('文件类型')
      console.log(file.name)
      console.log('文件类型111')
      console.log(file.name.indexOf('.mzshh'))
      const isMZSHH = file.name.indexOf('.mzshh') > 0
      if (!isMZSHH) {
        this.$message.error('只能上传扩展名为mzshh的民主生活会数据包文件')
      }
      return isMZSHH
    }
  },
  mounted () {
  }
}
</script>
<style scoped>
</style>
